package com.freesky.provider.order.controller;

import com.freesky.common.pojo.Result;
import com.freesky.common.utils.ResultUtil;
import com.freesky.common.utils.reponse.JSONResponse;
import com.freesky.common.vo.CartItem;
import com.freesky.common.vo.VOCart;
import com.freesky.provider.order.service.ICartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CartController {

    @Autowired
    private ICartService cartService;

    @PostMapping(value = "/member/addCart")
    public JSONResponse addCart(@RequestBody VOCart cart){

        return cartService.addCart(cart.getUserId(), cart.getProductId(), cart.getProductNum());
    }

    @PostMapping(value = "/member/cartList")
    public JSONResponse getCartList(@RequestBody VOCart cart){

        return cartService.getCartList(cart.getUserId());
    }

    @PostMapping(value = "/member/cartEdit")
    public JSONResponse updateCartNum(@RequestBody VOCart cart){
        return cartService.updateCartNum(cart.getUserId(), cart.getProductId(), cart.getProductNum(), cart.getChecked());
    }

    @PostMapping(value = "/member/editCheckAll")
    public JSONResponse editCheckAll(@RequestBody VOCart cart){
        return cartService.checkAll(cart.getUserId(), cart.getChecked());
    }

    @PostMapping(value = "/member/cartDel")
    public JSONResponse deleteCartItem(@RequestBody VOCart cart){
        return cartService.deleteCartItem(cart.getUserId(), cart.getProductId());
    }

    @PostMapping(value = "/member/delCartChecked")
    public JSONResponse delChecked(@RequestBody VOCart cart){
        return cartService.delChecked(cart.getUserId());
    }
}
